package interview.javabase.thread.condition;

//编写功能类,实现子线程和主线程的功能
@SuppressWarnings("all")
public class Function {

    //子线程要实现的功能
    public void sub() throws InterruptedException {
        // 190504 first 看了答案才做出来
    }

    //主线程要实现的功能
    public void main() throws InterruptedException {
        // TODO
    }
}












































/*
private boolean flag = false;

Lock lock = new ReentrantLock();

//相当于Object对象上的 wait (await) 和 notify (signal)
Condition con = lock.newCondition();

//子线程要实现的功能
public void sub() throws InterruptedException {

    lock.lock();

    try {
        while (flag)
            con.await();

        for (int i = 0; i < 10; i++)
            System.out.println("sub" + i);

        flag = true;
        con.signal();
    } finally {
        lock.unlock();
    }
}

//主线程要实现的功能
public void main() throws InterruptedException {

    lock.lock();

    try {
        while (!flag)
            con.await();

        for (int i = 0; i < 20; i++)
            System.out.println("main" + i);

        flag = false;
        con.signal();
    } finally {
        lock.unlock();
    }
}
*/